package com.daogu.fuelcard.controller;

import com.daogu.fuelcard.entity.TransactionRecord;
import com.daogu.fuelcard.service.TransactionRecordService;
import com.daogu.fuelcard.utils.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author daogu
 */
@Controller
@Tag(name = "交易记录实体类")
public class TransactionRecordController {

    @Autowired
    private TransactionRecordService transactionRecordService;

    @ResponseBody
    @PostMapping("/insertTransactionRecord")
    @Schema(description = "新增交易记录")
    public Result<Void> insert(@RequestBody  @Validated TransactionRecord transactionRecord) {
        return transactionRecordService.insert(transactionRecord);
    }

    @ResponseBody
    @PostMapping("/updateCheckStatus")
    @Schema(description = "修改交易记录状态")
    public Result<Void> updateCheckStatus(@RequestParam("id") Integer id,@RequestParam("checkStatus") Integer checkStatus) {
        return transactionRecordService.updateCheckStatus(id,checkStatus);
    }

    @ResponseBody
    @GetMapping("/getTransactionRecords")
    @Schema(description = "获取交易记录")
    public Result<PageInfo<TransactionRecord>> getTransactionRecord(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) {
        return transactionRecordService.getTransactionRecord(pageNum,pageSize);
    }

    @ResponseBody
    @PostMapping("/transaction/deletedById")
    @Schema(description = "删除交易记录")
    public Result<Void> deletedById(@RequestParam("id") Integer id) {
        return transactionRecordService.deletedById(id);
    }

    @Operation(description = "油卡交易页面页面")
    @GetMapping("/transactionRecord")
    public String login() {
        return "transaction-records";
    }

}
